package com.senseu.testserver.controller;

import com.senseu.testserver.model.Account;
import com.senseu.testserver.repository.AccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;

@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountRepository accountRepository;

    @PostMapping
    public Account saveAccount(@RequestBody Account account) {
        // 设置为可用
        account.setStatus(1);
        account.setCreateTime(new Timestamp(System.currentTimeMillis()));
        return accountRepository.save(account);
    }

    @GetMapping
    public List<Account> all() {
        return accountRepository.findAll();
    }
}
